package pers.hl.module_main

import pers.hl.common.base.BaseViewModel
import pers.hl.common.base.SingleLiveEvent
import pers.hl.lib_global.model.bean.BookTag
import pers.hl.lib_global.model.bean.Library
import pers.hl.lib_global.model.bean.User

class CommonEditViewModel: BaseViewModel<CommonEditModel>() {


    fun updateLibrary(library: Library): SingleLiveEvent<String> {
        val updateLibraryEvent = SingleLiveEvent<String>()
        launchOnIO {
            val result = mModel.updateLibrary(library)
            updateLibraryEvent.postValue(result.msg)
        }
        return updateLibraryEvent
    }

    fun updateTag(tag: BookTag): SingleLiveEvent<String> {
        val updateTagEvent = SingleLiveEvent<String>()
        launchOnIO {
            val result = mModel.updateTag(tag)
            updateTagEvent.postValue(result.msg)
        }
        return updateTagEvent
    }

    fun addTag(tag: BookTag): SingleLiveEvent<String> {
        val addTagEvent = SingleLiveEvent<String>()
        launchOnIO {
            val result = mModel.addTag(tag)
            addTagEvent.postValue(result.msg)
        }
        return addTagEvent
    }

    fun updateUser(user: User): SingleLiveEvent<String> {
        val addUserEvent = SingleLiveEvent<String>()
        launchOnIO {
            val result = mModel.updateUser(user)
            addUserEvent.postValue(result.msg)
        }
        return addUserEvent
    }

}
